app.controller('loginController', function($scope,$http) {

    $scope.user = {
        username:"",
        password:""
    };

    $scope.URL = {
        LOGIN_URL:"/login",
        ADMIN_URL:"/index"
    };

    //校验参数
    $scope.validateParam = function(){
        if(isNull($scope.user.username)){
            layer.msg("请输入用户名");
            return true;
        }
        if(isNull($scope.user.password)){
            layer.msg("请输入密码");
            return true;
        }
        return false;
    };

    $scope.login = function(){
        if($scope.validateParam()){
            return false;
        }
        $('#subBtn')[0].disabled = true;
        //提交数据
        $http({method : 'POST', data:$scope.user, url : $scope.URL.LOGIN_URL})
            .success(function(data,status,headers,config){
                //console.log(data);
                $('#subBtn')[0].disabled = false;
                if(data.code == 0){
                    window.location.href = $scope.URL.ADMIN_URL;
                }else{
                    layer.alert(data.msg, {
                        icon: 5,
                        skin: 'layer-ext-moon' //该皮肤由layer.seaning.com友情扩展。关于皮肤的扩展规则，去这里查阅
                    })
                }
            }).error(function(data,status,headers,config){
            $('#subBtn')[0].disabled = false;
            console.log('error..........');
            console.log(data);
        });
    };

});